package com.company;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * 通道拷贝文件  channel
 */
public class Main {

    private static final int SIZE=1024;

    public static void main(String[] args) throws IOException {
	// write your code here
        FileChannel inChannel = new FileInputStream("d:\\line.png").getChannel();
        FileChannel outChannel = new FileOutputStream("d:\\line999.png").getChannel();

        //分配字节缓冲区
        ByteBuffer buffer = ByteBuffer.allocate(SIZE);
        while (inChannel.read(buffer) != -1) {
            // 切换缓冲区的读写模式
            buffer.flip();
            outChannel.write(buffer);
            buffer.clear();
        }
        inChannel.close();
        outChannel.close();
    }







}
